package com.ranjiaqi.upload;

import java.io.*;
import java.net.Socket;

/**
 * @ClassName upload
 * @Description TODO
 * @Author hp
 * @Date 2021/7/2 21:12
 * @Version 1.0
 **/
public class UploadClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost",8888);
        BufferedInputStream reader = new BufferedInputStream(new FileInputStream("F:/java/1.txt"));
        BufferedOutputStream bos= new BufferedOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[1024*5];
        int x ;
        while ((x=reader.read(bytes))!=-1){
               bos.write(bytes,0,x);
               bos.flush();
        }

        socket.shutdownOutput();
        BufferedInputStream bis= new BufferedInputStream(socket.getInputStream());

        int len = bis.read(bytes);
        System.out.println(new String(bytes,0,len));
        bis.close();
        socket.close();

    }
}
